#!/usr/bin/perl

use strict;
use CGI;

require 'config.pl';

my $cgi = new CGI;
my $all_online = 1;

print "Content-type: text/html\n\n";

if ($cgi->param()) {

    unless($cgi->param('links')) {
        print "Direct access not permitted. Exiting.\n";
        exit 0;
    }

    foreach my $line (split /\r?\n/, $cgi->param('links')){
        if(`curl -s $line | sed -n -e '/Free user/p'` eq "") {
            print "\"" . $line . "\" ist offline.\n";
            $all_online = 0;
        }
    }

    if($all_online) {
        print 1;
    }

} else {
    # es wurde noch nicht abgeschickt, also muss ich es anzeigen
    print "Required POST-Variables are missing. Exiting.\n";
    exit 0;
}